package com.inno.auth.controller.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.inno.auth.common.entity.CommonReturnType;
import com.inno.auth.domain.entity.MemberBO;
import com.inno.auth.domain.service.MemberDomainService;
import com.inno.auth.entity.MemberDTO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author shenzeyang
 */
@RestController
@RequestMapping("/auth/member")
public class MemberController {

    @Resource
    private MemberDomainService memberDomainService;
    /**
     * 赠送会员接口
     * @Description: 系统内部访问
     */
    @PostMapping("/gifts")
    public CommonReturnType<Void> gifts(@RequestBody MemberDTO memberDTO) {
        if (Objects.isNull(memberDTO.getUserId())){
            return CommonReturnType.fail("userId不能为空");
        }
        if (Objects.isNull(memberDTO.getEndTime())){
            return CommonReturnType.fail("到期时间不能为空");
        }
        this.memberDomainService.gifts(convertDTOToBO(memberDTO));
        return CommonReturnType.success();
    }

    private static MemberBO convertDTOToBO(MemberDTO memberDTO){
        MemberBO memberBO = new MemberBO();
        BeanUtil.copyProperties(memberDTO, memberBO);
        return memberBO;
    }
}
